package com.framework.plugin.xmlsql.tag;

import java.util.Map;

import ognl.Ognl;
import ognl.OgnlException;

public class IfTag extends DefaultTag {
	
	private boolean flag;

	public boolean isFlag() {
		return flag;
	}

	public void setFlag(boolean flag) {
		this.flag = flag;
	}
	
	public IfTag(Map<String, Object> map) {
		super.setMap(map);
	}

	@Override
	public String createSql(String text) {
		if(flag)
			return text;
		else
			return "";
	}

	@Override
	public void prepare() {
		String expression = attr("test");
		try {
			boolean value = (Boolean)Ognl.getValue(expression, getMap());
			flag = value;
		} catch (OgnlException e) {
			e.printStackTrace();
		}
	}

}
